/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.TallySetDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class TallySetDaoImpl extends BaseDaoImpl implements TallySetDao {
	public List getList(boolean justEnabled) {
		String sql = "from com.minierp.model.TallySet c";
		if (justEnabled) {
			sql = sql + " where c.enabled=\'Y\'";
		}

		sql = sql + " order by c.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getList(long userId) {
		String sql = "select c from com.minierp.model.TallySet c,com.minierp.model.UserPo u where c.id=u.poId and u.poType=\'TS\' and u.userId="
				+ userId + " and c.enabled=\'Y\'" + " order by c.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getList(String title, long expId) {
		String sql = "from com.minierp.model.TallySet c where c.enabled!=\'N\' and c.title=:title and id!="
				+ expId;
		Session sess = null;

		List arg7;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			q.setString("title", title);
			arg7 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg7;
	}

	public int recover(final String title) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "update com.minierp.model.TallySet set enabled=\'Y\' where title=:title";
						Query q = session.createQuery(hql);
						q.setString("title", title);
						return new Integer(q.executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}
}